package com.yic.module.device.controller.admin.inspectionPlanMessage;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.yic.framework.common.pojo.PageResult;
import com.yic.framework.common.pojo.CommonResult;
import static com.yic.framework.common.pojo.CommonResult.success;

import com.yic.framework.excel.core.util.ExcelUtils;

import com.yic.framework.operatelog.core.annotations.OperateLog;
import static com.yic.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.yic.module.device.controller.admin.inspectionPlanMessage.vo.*;
import com.yic.module.device.dal.dataobject.inspectionPlanMessage.InspectionPlanMessageDO;
import com.yic.module.device.convert.inspectionPlanMessage.InspectionPlanMessageConvert;
import com.yic.module.device.service.inspectionPlanMessage.InspectionPlanMessageService;

@Tag(name = "管理后台 - 设备计划消息管理")
@RestController
@RequestMapping("/device/inspection-plan-message")
@Validated
public class InspectionPlanMessageController {

    @Resource
    private InspectionPlanMessageService inspectionPlanMessageService;

    @PostMapping("/create")
    @Operation(summary = "创建设备计划消息管理")
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:create')")
    public CommonResult<Long> createInspectionPlanMessage(@Valid @RequestBody InspectionPlanMessageCreateReqVO createReqVO) {
        return success(inspectionPlanMessageService.createInspectionPlanMessage(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新设备计划消息管理")
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:update')")
    public CommonResult<Boolean> updateInspectionPlanMessage(@Valid @RequestBody InspectionPlanMessageUpdateReqVO updateReqVO) {
        inspectionPlanMessageService.updateInspectionPlanMessage(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除设备计划消息管理")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:delete')")
    public CommonResult<Boolean> deleteInspectionPlanMessage(@RequestParam("id") Long id) {
        inspectionPlanMessageService.deleteInspectionPlanMessage(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得设备计划消息管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:query')")
    public CommonResult<InspectionPlanMessageRespVO> getInspectionPlanMessage(@RequestParam("id") Long id) {
        InspectionPlanMessageDO inspectionPlanMessage = inspectionPlanMessageService.getInspectionPlanMessage(id);
        return success(InspectionPlanMessageConvert.INSTANCE.convert(inspectionPlanMessage));
    }

    @GetMapping("/list")
    @Operation(summary = "获得设备计划消息管理列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:query')")
    public CommonResult<List<InspectionPlanMessageRespVO>> getInspectionPlanMessageList(@RequestParam("ids") Collection<Long> ids) {
        List<InspectionPlanMessageDO> list = inspectionPlanMessageService.getInspectionPlanMessageList(ids);
        return success(InspectionPlanMessageConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得设备计划消息管理分页")
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:query')")
    public CommonResult<PageResult<InspectionPlanMessageRespVO>> getInspectionPlanMessagePage(@Valid InspectionPlanMessagePageReqVO pageVO) {
        PageResult<InspectionPlanMessageDO> pageResult = inspectionPlanMessageService.getInspectionPlanMessagePage(pageVO);
        return success(InspectionPlanMessageConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出设备计划消息管理 Excel")
    @PreAuthorize("@ss.hasPermission('device:inspection-plan-message:export')")
    @OperateLog(type = EXPORT)
    public void exportInspectionPlanMessageExcel(@Valid InspectionPlanMessageExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<InspectionPlanMessageDO> list = inspectionPlanMessageService.getInspectionPlanMessageList(exportReqVO);
        // 导出 Excel
        List<InspectionPlanMessageExcelVO> datas = InspectionPlanMessageConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "设备计划消息管理.xls", "数据", InspectionPlanMessageExcelVO.class, datas);
    }

}
